#pragma GCC optimize("-O2")
#include <cstdio>

using namespace std;

typedef long long ll;
const int maxk=300, maxn=301, mods=1000000007;

ll fact[maxk*maxn+1], invf[maxk*maxn+1];

ll qpower(ll a, int n) {
    ll s=1;
    for (; n; n/=2) {
        if (n&1) s=s*a%mods;
        a=a*a%mods;
    }
    return s;
}

void initFact(int n) {
    fact[0] = 1;
    for (int i=1; i<=n; i++) fact[i] = fact[i-1]*i%mods;
    invf[n] = qpower(fact[n], mods-2);
    for (int i=n; i>0; i--) invf[i-1] = invf[i]*i%mods;
}

int main() {
    freopen("nothard.in", "r", stdin);
    freopen("nothard.out", "w", stdout);

    static int a[maxk+1][maxn+1], p[maxn+1][maxk+1];
    int k, n;
    scanf("%d %d", &k, &n);
    initFact(n*k);
    for (int i=1; i<=k; i++) {
        for (int j=1; j<=n; j++) {
            scanf("%d", a[i]+j);
            p[i][a[i][j]] = j;
        }
        a[i][n+1] = p[i][n+1] = n+1;
    }
    n++;

    static int cor[2][maxn+1][maxn+1];
    static ll f[maxn+1], u[maxn+1][maxn+1], v[maxn+1][maxn+1];
    ll ans=0, now=0;
    for (int i=1; i<=k; i++) {
        int pos=0;
        for (int j=1; j<=n; j++) {
            int o=a[i][j];
            cor[pos][o][0] = j-1;
            u[o][o]=j-1;
            v[o][o]=invf[j-1];
            for (int t=1; t<j; t++) {
                cor[pos][o][t] = a[i][t];
                u[o][a[i][t]] = j-t-1;
                v[o][a[i][t]] = invf[j-t-1];
            }
        }

        for (int j=i+1; j<=k; j++) {
            static int book[maxn+1];
            book[0]++;
            pos=!pos;
            for (int x=1; x<=n; x++) {
                int o=a[j][x];
                u[o][o] += x-1;
                v[o][o] = v[o][o]*invf[x-1]%mods;
                f[o] = fact[u[o][o]]*v[o][o]%mods*fact[j-i+1]%mods;

                cor[pos][o][0] = 0;
                for (int y=1; y<=cor[!pos][o][0]; y++) {
                    int z=cor[!pos][o][y];
                    if (book[z]==book[0]) {
                        cor[pos][o][++cor[pos][o][0]] = z;

                        int t=x-p[j][z]-1;
                        u[o][z] += t;
                        v[o][z] = v[o][z]*invf[t]%mods;
                        f[o] = (f[o]+mods-f[z]*fact[u[o][z]]%mods*v[o][z]%mods*fact[j-i+1]%mods)%mods;
                    }
                }
                book[o] = book[0];
            }

            ans = (ans+f[n]*invf[j-i+1]%mods)%mods;
        }
    }

    printf("%lld\n", ans);

    fclose(stdin);
    fclose(stdout);
    return 0;
}
